<?php

namespace app\model;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ServerType extends Base
{

    protected $table = 'server_type';
    protected $connection;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->connection = config('database.connections.biqi_game.database');
    }


    public function AliInstance(): BelongsTo
    {
        return $this->belongsTo(AliYunEcsConfig::class, 'instance', 'ulid');
    }

    public function TencentInstance(): BelongsTo
    {
        return $this->belongsTo(TencentCloudCvmConfig::class, 'instance', 'ulid');
    }


    protected function equity(): Attribute
    {
        return Attribute::make(
            get: fn(mixed $value) => json_decode($value, true),
        )->withoutObjectCaching();
    }

}
